<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://suryani.cn/support/tags" prefix="page"%>

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>评论管理-评论列表</title>
<base href="${base }" />
<!-- Le HTML5 shim, for IE6-8 support of HTML elements -->
<!--[if lt IE 9]>
	<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<!--[if lte IE 8]>
	<script language="javascript" type="text/javascript" src="excanvas.min.js"></script>
<![endif]-->
<link rel="stylesheet/less" type="text/css" href="less/default.less">
<script type="text/javascript" src="js/less.min.js"></script>
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/jquery.stickymenu.js"></script>
<script type="text/javascript" src="js/emm-1.0.js"></script>
<script type="text/javascript" src="js/jquery.topLink.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/jquery.flot.min.js"></script>
<script type="text/javascript" src="js/jquery.dataTables.js"></script>
<script type="text/javascript" src="js/jquery.validate.min.js"></script>
<script type="text/javascript">
    var oTable = null;
	$(document).ready(function() {
		oTable=$("#commentTable").dataTable({
			"oLanguage" : {
				"sUrl" : "js/i18n/table_zh.txt"
			},
			"aoColumns" : [ {
				"mDataProp" : "status",
				"sWidth" : "5px",
				"bUseRendered": false,
				"fnRender" : function(obj){
					return "<input type='checkbox' name='checkbox'>";
				}
			}, {
				"mDataProp" : "id",
				"sWidth" : "25px"
			}, {
				"mDataProp" : "score",
				"sWidth" : "15px"
			}, {
				"mDataProp" : "comment",
				"sWidth" : "150px"
			}, {
				"mDataProp" : "auditStatus",
				"sWidth" : "30px",
				"bUseRendered": false,
				"fnRender" : function(obj){ 
					if(obj.aData.auditStatus == 0){
						return "未审核";
					}
					if(obj.aData.auditStatus == 1){
						return "审核不通过";
					}
					if(obj.aData.auditStatus == 2){
						return "审核通过";
					}
				}
			}, {
				"mDataProp" : "status",
				"sWidth" : "50px",
				"bUseRendered": false,
				"fnRender" : function(obj){
					if(!obj.aData.user){
						return "";
					}else{
						return obj.aData.user.username;
					}
					}
			}, {
				"mDataProp" : "createTime",
				"sWidth" : "100px"
			}, {
				"mDataProp" : "lastUpdateTime",
				"sWidth" : "100px",
				"fnRender" : function(obj){  
					if(obj.aData.auditStatus==0){
						return "<div class='btn-group'><a class='btn' href='javascript:void(0);' data-id="+obj.aData.id+" onclick='auditPassComment(this)'>审核通过</a><a class='btn' href='javascript:void(0);' data-id="+obj.aData.id+" onclick='auditNotPassComment(this)'>审核不通过</a><a class='btn' href='javascript:void(0);' data-id="+obj.aData.id+" onclick='deleteItem(this)'>删除</a></div>";
					}
					return "<div class='btn-group'><a class='btn' href='javascript:void(0);' data-id="+obj.aData.id+" onclick='deleteItem(this)'>删除</a></div>";
				}
			}],
			"bFilter" : false,
			"bSort" : false,
			"bProcessing" : true,
			"bPaginate" : true,
			"aLengthMenu" : [[5, 10, 15, 20, 30], [5, 10, 15, 20, 30]],
			"sPaginationType" : 'full_numbers',
			"bServerSide" : true,
			"fnServerData" : function(sSource, aoData, fnCallback) {
				var data = {};
				$("#searchForm")
				.find("input[type='text'], select option:selected")
				.each(function() {
					data[ this.name || this.parentNode.name] = this.value;
				});
				var aoDataMap = toAoDataMap(aoData);
				data.offset = aoDataMap.iDisplayStart;
				data.fetchSize = aoDataMap.iDisplayLength;
				$.ajax({
					"dataType" : 'json',
					"type" : "POST",
					"url" : "comment/list",
					"data" : data,
					"success" : function(data) {
						var aoData = {
							iDisplayStart : data.offset,
							iDisplayLength : data.fetchSize,
							aaData : data.data,
							iTotalDisplayRecords : data.total,
							iTotalRecords : data.total
						};
						fnCallback(aoData);
					}
				});
			}
		});
		
		$("#searchForm").submit(function(e){
			oTable.fnPageChange( 'first' );
			return false;
        });

	});
</script>
</head>
<body>
	<div class="page">
		<page:view page="/common/left?menu=comment" />
		<div id="main" class="main container">
			<page:view page="/common/header?parentTitle=评论管理&childTitle=评论列表" />
			<div id="menu" class="row-fluid menu">
			    <div class="buttons">
					  <button class="btn" onClick="batchDelete()">批量删除</button>
				</div>
				<form class="form-search" id="searchForm">
					<input type="text" name="queryParam" id="queryParam" class="input-medium search-query"
						placeholder="请输入分数如，5"> 
						<span class="block">
							<div class="btn-group">
								<input type="submit" class="btn btn-primary" value="搜索">
							</div>
						</span>
				</form>
			</div>
			<div class="row-fluid">
				<div class="widget">
					<div class="inner">
						<table id="commentTable">
							<thead>
								<tr>
									<th width="5px"><input type="checkbox" name='checkAll' id='checkAll' onClick='selectAll()'></th>
									<th width="25px">评论ID</th>
									<th width="15px">分数</th>
									<th width="150px">内容</th>
									<th width="30px">审核状态</th>
									<th width="50px">用户</th>
									<th width="100px">创建时间</th>
									<th width="100px">操作</th>
								</tr>
							</thead>
							<tbody>
							</tbody>
						</table>
					</div>
				</div>
			</div>
			<div class="container">
				<page:view page="/common/footer" />
			</div>
		</div>
	</div>
<script type="text/javascript">
function deleteItem(obj){
	var trObj = $(obj).parents("tr").get(0);
    var id=$(obj).attr("data-id");
	if(!confirm("你确定要删除ID为 ["+id+"]的评论吗?")){
		return ;
	}	
	var url="comment/delete?id="+id;
		$.ajax({
			type: 'POST',
	  		url: url,
	  		data:"",
	  		success: function(returnMessage){
	    		if(returnMessage=="success"){
	    			var ipage = getDateTablePageInfo(oTable.fnSettings()).iPage; 
					oTable.fnPageChange(ipage);
	    		}else{
	    			alert("删除失败！");
	    		}
				}
		});
}	

function auditPassComment(obj){
	var trObj = $(obj).parents("tr").get(0);
    
    var id=$(obj).attr("data-id");
    var data={};
    data.id=id;
	var url="comment/auditpass";
		$.ajax({
			type: 'POST',
	  		url: url,
	  		data:data,
	  		success: function(returnMessage){
	    			var ipage = getDateTablePageInfo(oTable.fnSettings()).iPage; 
					oTable.fnPageChange(ipage);
				}
		});
}

function auditNotPassComment(obj){
	var trObj = $(obj).parents("tr").get(0);
    
    var id=$(obj).attr("data-id");
    var data={};
    data.id=id;
	var url="comment/auditnotpass";
		$.ajax({
			type: 'POST',
	  		url: url,
	  		data:data,
	  		success: function(returnMessage){
	    			var ipage = getDateTablePageInfo(oTable.fnSettings()).iPage; 
					oTable.fnPageChange(ipage);
				}
		});
}

function selectAll(){
    if($("#checkAll").attr("checked")=="checked"){
   		$("input[name='checkbox']").each(function (e){
   		      if($(this).attr('disabled') != 'disabled'){
   		          $(this).attr("checked", true);
   		      }
   		});
     }else{
   		$("input[name='checkbox']").attr("checked", false);
   		}
  }

function batchDelete(){
	var batchSize=$("input[name='checkbox']:checked").size();
    if(batchSize==0){
       alert("请选择要删除的记录.");
       return "";
    }
    if(!confirm("你确定删除这些记录吗？")){
			return "";
		}
		var ids="";
    $("input[name='checkbox']:checked").each(function(e){
          var trObj = $(this).parents("tr").get(0);
          id=oTable.fnGetData(trObj).id;
          ids +=id;
          ids +=",";
		});
		var data={};
		data.ids=ids;
		var url="comment/batchdelete";
			$.ajax({
				type: 'POST',
		  		url: url,
		  		data:data,
		  		success: function(returnMessage){
		    		if(returnMessage=="success"){
		    			if(batchSize==1){
		    				var ipage = getDateTablePageInfo(oTable.fnSettings()).iPage; 
							oTable.fnPageChange(ipage);
		    			}else{
		    				var ipage = getDateTablePageInfoAfterBatchDelete(oTable.fnSettings(),batchSize).iPage; 
							oTable.fnPageChange(ipage);
		    			}
		    		}else{
		    			alert("删除失败！");
		    		}
				}
			});
  }

</script>
</body>
</html>